#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[1001], b[1001], c[1001];
int f[1001][1001];

int main() {
    cin >> m >> n >> k;
    memset(f, 0x7f, sizeof(f));
    f[0][0] = 0;
    for (int i = 1; i <= k; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 1; i <= k; i++) {
        for (int v = m; v >= 0; v--) {
            for (int u = n; u >= 0; u--) {
                int t1 = v + a[i];
                int t2 = u + b[i];
                if (t1 > m)
                    t1 = m;
                if (t2 > n)
                    t2 = n;

                f[t1][t2] = min(f[t1][t2],f[v][u]+c[i]);
            }
        }
    }

    cout <<f[m][n];

    return 0;
}